window.onload = rollover;

function rollover() {
	for (var i = 0; i < document.images.length; i++) {
		// 检测图像是否被<a>标签包围
		if (document.images[i].parentNode.tagName == "A") {
			setupRollover(document.images[i]);
		}
	}
}

// outImage和overImage是新声明的两个属性, 属性本身也是图像对象
function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = function() {
		// 这里的this指向的是thisImage
		this.src = this.outImage.src;
	};

	thisImage.overImage = new Image();
	thisImage.overImage.src = "../images/" + thisImage.id + "_on.gif";
	thisImage.onmouseover = function() {
		this.src = this.overImage.src;
	};
}